﻿using HystereticBasic;
using HystereticRegularization;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace HystereticBasic
{
    class Example
    {
        /// <summary>
        /// 实例代码
        /// </summary>
        public static void Demo()
        {
            //构造力位移曲线数据
            var dispList = new List<float>();
            var forceList = new List<float>();
            //处理滞回环数据
            var dataObj = new BasicData(@"C:\Users\SCUT\Desktop\新建文件夹\1.txt", 2);
            //获得所有加载历史
            //var histroy = dataObj.CircleSet.GetLoadingHistory();
            //var dataObj = new BasicData(dispList, forceList, isDisp, isFilter);

            //获得累积耗能面积
            var energyList = dataObj[DataType.AccumulateEnergy];
            //获得刚度退化系数
            var sDegradationList = dataObj[DataType.SecantStiffnessRatio];

            //获得每个滞回环
            var circleList = dataObj.CircleSet.GetCircleList(false, false);
            //获得第一个滞回环对象
            var circle1st = circleList.First();
            //遍历滞回环
            foreach(var circle in circleList)
            {
                //滞回环的最大变形、最大力点
                var dispMaxPtr = circle.GetPeakOrientPt(true);
                var dispMinPtr = circle.GetPeakOrientPt(false); 
                var forceMaxPtr = circle.GetPeakForcePt(true);
                var forceMinPtr = circle.GetPeakForcePt(false);
                // 通过点获得对应的位移和变形
                var dispMax = dispMaxPtr.Disp;
                var forceMax = forceMaxPtr.Force;
                //滞回环面积
                var A = circle.GetA();
            }

            //获得正向 及负向的骨架曲线
            var posSkeleton = dataObj.GetSkeletonObj(true);
            var negSkeleton = dataObj.GetSkeletonObj(false);

            //延性系数计算 定义极限状态下的承载力退化系数、Park系数
            var obj = new DuctilityObj(dataObj, true, 0.9F, 0.7F);
            //获得对应方法下的延性系数值
            var factor = obj[DataType.DuctilityFactor, DuctilityMethod.Energy];
            //屈服力
            var force = obj[DataType.DuctilityYieldForce, DuctilityMethod.General];

            //获得数值骨架曲线
            var numericalPosSkeleton = posSkeleton.GetNumericalSkeleton();
        }

        public static void LXMDemo()
        {
            //路径
            var directPath = @"G:\Gitee\滞回与骨架数据处理\SpecimenTest\20220123\延性系数(3)";
            //所有文件路径
            var filePathList = HystereticHelper.GetFileList(directPath);
            //处理滞回环数据
            var dataObjSet = new HyDataSet(filePathList, SkeletonSoftenMethod.SecantAllCycle);
            //字典
            var diction = new Dictionary<string, double>();
            //遍历构件
            foreach(var data in dataObjSet.DataList)
            {
                //获得正向骨架
                
                var skeleton = data.GetSkeletonObj(true);
                //var skeleton = new MontForceDispObj(data.OriginalCurveObj.ToList());
                //获得上升段能量
                var upEnergy = skeleton.GetA(true);
                //获得下降段
                var softenObj = skeleton.PostPeakSkeleton;
                //目标力
                var targetFroce = skeleton.ForceMaxPoint.Force * 0.75F;
                //插值获得对应点
                ForceDispBasicPair targetPt;
                if(softenObj.GetPtByForce(targetFroce, out targetPt))
                {
                    //目标下降段
                    var targetObj = softenObj.Seperate(targetPt, true);
                    //计算能量
                    var downEnergy = targetObj.Item1.GetEnergy();
                    //计算延性系数
                    var ducFactor = (downEnergy + upEnergy) / upEnergy;
                    //添加对象
                    diction.Add(data.FileName, ducFactor);
                }
            }
        }
    }
}
